import React, { Component } from 'react';
/**
 * 1.下载 npm i immutable
 * 2.导入 import {Map} from 'immutable'
 */
import {Map} from 'immutable'

var obj={
    name:"碰磕",
    age:20
}
var objImmu=Map(obj);
var newobjImmu=objImmu.set("name","pengkeStudy");
// console.log(objImmu,newobjImmu)
//get('属性')获取值
console.log(objImmu.get("name"),newobjImmu.get("name"));

//toJS转回普通对象
console.log(objImmu.toJS(),newobjImmu.toJS());
/*
//写法一
class Immu02 extends Component {
    state={
        info:Map({
            name:"碰磕",
            age:20
        })
    }
    render() {
        return (
            <div>
                Immu02
                <button onClick={()=>{
                    this.setState({
                        info:this.state.info.set('name',"pengkeStudy").set('age',1000)
                    })
                }}>修改它们的值</button>
                {this.state.info.get("name")}----
                {this.state.info.get("age")}
            </div>
        );
    }
}*/
//写法二
class Immu02 extends Component {
    state={
        info:{
            name:"碰磕",
            age:20
        }
    }
    render() {
        return (
            <div>
                Immu02
                <button onClick={()=>{
                    let old=Map(this.state.info)
                    let newImmu=old.set("name","pengkeStudy").set("age",10000)
                    this.setState({
                        info:newImmu.toJS()
                    })
                    
                }}>修改它们的值</button>
                {this.state.info.name}----
                {this.state.info.age}
            </div>
        );
    }
}

export default Immu02;